<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class NoticeSetController extends AdminBaseController {

    public function index(){
        $this->setTitle('公告设置列表');

        $filter = new PubFilter();
        $grid   = new PubGrid();
     
        //$filter->addOssServer(true);
        $filter->addFilter('title', 'input', '标题');
           
        $params = $filter->get();
        $header = NoticeSetService::indexHeader();
        $data   = NoticeSetService::indexData($params);
        
        $grid->addGrid($header, $data);

        $this->out['filter'] = $filter->show();
        $this->out['grid'] = $grid->show();
        
    }
    
    
    public function add(){
    	$this->setTitle('添加公告');
    	$this->out['serverList'] = ServerService::getOptions();
    	$this->out['templetList']    = NoticeTempletService::lists();
    	$this->out['synchroTypeList'] = NoticeSetService::synchroTypeList();
    	$this->out['isEjectList'] = NoticeSetService::isEjectList();
    	$this->out['isBindList'] = NoticeSetService::isBindList();
    }
    
    public function doAdd(){
    	$result = NoticeSetService::doAdd($_POST);
    	 
    	if($result['state']){
    		$this->showMessage('添加成功', PubFunc::buildUrl('/oss/?r=noticeSet/index'));
    	}else{
    		$this->showMessage($result['msg']);
    	}
    }
    
    public function edit(){
    	$id = $this->R('id');
    	$info = NoticeSetService::get($id);
    	    	
    	if(empty($info)) $this->showMessage('找不到该信息');
    
    	$this->setTitle('编辑公告', $info['name']);
    
    	$this->out['info'] = $info;
    	
    	$typeList = explode(',', $info['type']);
    	$this->out['typeList'] = $typeList;
    	
    	$this->out['isEjectList'] = NoticeSetService::isEjectList();
    }
    
    public function doEdit(){
    	$id = $this->R('id');
    	$result = NoticeSetService::doEdit($id, $_POST);
    
    	if($result !== false){
    		$this->showMessage('编辑成功', PubFunc::buildUrl("/oss/?r=noticeSet/index"));
    	}else{
    		$this->showMessage('编辑失败');
    	}
    }
    
    
    public function delete(){
    	$id = $this->R('id');
    
    	$result = NoticeSetService::delete($id);
    
    	if($result !== false){
    		$this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=noticeSet/index"));
    	}else{
    		$this->showMessage('删除失败');
    	}
    }
    
    
    public function synchro(){
    	$ids = PubRequest::R('ids');
    	if(PubFunc::isAjax()){
    		$servers = PubRequest::R('servers');
    		$result = NoticeSetService::synchro($ids,$servers);
    		$this->out = array(
    				'status' => 1,
    				'msg' => $result,
    				'data'    => ''
    		);
    		$this->outType = 'json';
    	}else{
    
    		$list = PubServer::getChannelServer();
    
    		$this->out['list'] = $list;
    		$this->out['ids'] = $ids;
    		$this->layout = '';
    
    		$url = PubFunc::buildUrl("/oss/?r=noticeSet/synchro");
    		$this->out['url'] = $url;
    
    
    	}
    }
    
    
   public function timimg(){
   	   $result = NoticeSetService::timimg();
   	   echo $result;
   }

   
   public function textapi(){
   	   $json_array = array();
   	   
   	   $key = 'BF1A9DAFF92587A7FC93A6BB59230DA8';
   	   $json_array['id'] = 8;
   	   $json_array['server_name'] = 'yuxun';
   	   $json_array['develop_id'] = 'xxxxx24911111';
   	   $json_array['server_num'] = '11';
   	   $json_array['oss_api'] = 'http://192.168.1.10:11111/gm/';
   	   $json_array['log_server'] = '192.168.1.10';
   	   $json_array['ip'] = '192.168.1.10';
   	   $json_array['port'] = '3306';
   	   $json_array['open_time'] = '1536132303';
   	   $json_array['union_time'] = '1536132303';
   	   $json_array['union_to'] = '';
   	   $json_array['status'] = '1';
   	   $json_array['channel_list'] = '211,199';
   	   $json_array['special_id'] = 'ys100';
   	   $json = json_encode($json_array);
   	   $params = array();
   	   $params['json_data'] = $json;
   	   $time = time();
   
   	   ksort($params);
   	   foreach($params as $k=>$v){
   	   	  $str .= $k.$v;
   	   }
   	   
   	   $str = $str.$time.$key;
   	   $sign = strtoupper(md5($str));
   	   
   	   $data = array();
   	   $data = $params;
   	   $data['time'] = $time;
   	   $data['sign'] = $sign;

   	   $url = 'http://www.tm.com/api/?r=server/addServer';
   	   $result = PubFunc::request($url, $data, 10);
   	   echo '<pre>';
   	   var_dump($result);exit;
   	   
   }
   
   public function textapi1(){
   	   $key = 'BF1A9DAFF92587A7FC93A6BB59230DA8';
   	   $params = array();
   	   $time = time();
   	 
   	   ksort($params);
   	   foreach($params as $k=>$v){
   		   $str .= $k.$v;
   	   }
   		
   	   $str = $str.$time.$key;
   	   $sign = strtoupper(md5($str));
   		
   	   $data = array();
   	   $data = $params;
   	   $data['time'] = $time;
   	   $data['sign'] = $sign;
   
   	   $url = 'http://www.tm.com/api/?r=quxuan/getPlatList';
   	   $result = PubFunc::request($url, $data, 10);
   	   echo '<pre>';
   	   var_dump($result);exit;	
   }
   
   public function textapi2(){
   	   $key = 'BF1A9DAFF92587A7FC93A6BB59230DA8';
   	   $params = array();
   	   $time = time();
   	 
   	   ksort($params);
   	   foreach($params as $k=>$v){
   		   $str .= $k.$v;
   	   }
   	 
   	   $str = $str.$time.$key;
   	   $sign = strtoupper(md5($str));
   	 
   	   $data = array();
   	   $data = $params;
   	   $data['time'] = $time;
   	   $data['sign'] = $sign;
   	 
   	   $url = 'http://www.tm.com/api/?r=quxuan/getServerList';
   	   $result = PubFunc::request($url, $data, 10);
   	   echo '<pre>';
   	   var_dump($result);exit;
   }
    

}